using System;
using System.Reflection;
using System.Windows.Forms;

using Elev.Core;

namespace Elev.UI
{
    public partial class AboutForm : Form
    {
        public AboutForm()
        {
            InitializeComponent();

            setVersion();
            setCopyright();
            setNETVersion();
        }

        void setVersion()
        {
            Assembly exeAssembly = Assembly.GetExecutingAssembly();
            Assembly coreAssembly = typeof(Context).Assembly;
            string exeVersion = string.Format("UI build {0}", exeAssembly.GetName().Version.Revision);
            string coreVersion = string.Format("Lib build {0}", coreAssembly.GetName().Version.Revision);
            versionLabel.Text = string.Format("Version {0} BETA ({1}, {2})", Application.ProductVersion, exeVersion, coreVersion);
        }

        void setCopyright()
        {
            copyrightLabel.Text = "Copyright 2007 (c) JctSoft.";
        }

        void setNETVersion()
        {
            string version = Environment.Version.ToString();
            frameworkVersionLabel.Text = string.Format("[ .NET Version {0} ]", version);
        }

        void LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            string target = ((LinkLabel)sender).Text;
            if (target != null && target.StartsWith("http"))
            {
                System.Diagnostics.Process.Start(target);
            }
        }

        void okButton_Click(object sender, EventArgs e)
        {
            Close();
        }

        void Form_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Return:
                case Keys.Escape:
                    Close();
                    break;
            }
        }
    }
}